package Util;

public class Stack <A>
{
    private Node <A> first = null;
    private int length = 0;

    public A getFirst()
    {
        return (this.first != null) ? this.first.getValue() : null;
    }

    public boolean isEmpty()
    {
    	return (this.first == null);
    }

    public int getLength()
    {
    	return this.length;
    }

    public A pop()
    {
        if (this.first == null)
        {
            return null;
        }
        else
        {
            A temp = this.first.getValue();
            this.first = this.first.getNext();
            this.length --;
            return temp;
        }
    }

    public void push(A obj)
    {
        this.first = new Node<A>(obj, this.first);
        this.length ++;
    }

    class Node <B>
    {
        private Node<B> next;
        private B value;

        public Node(B value)
        {
        	this(value, null);
        }

        public Node(B value, Node<B> next)
        {
            this.next = next;
            this.value = value;
        }
        
        public Node<B> getNext()
        {
        	return this.next;
        }
        
        public B getValue()
        {
        	return this.value;
        }
    }
    
}